package net.asfun.jvalog.http;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class JvalogFilter implements Filter{
	
	private String[] refuse;

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		String uri = ((HttpServletRequest)request).getRequestURI().substring(1);
		for(int i=0; i<refuse.length; i++) {
			//TODO 
			if ( uri.equals(refuse[i]) ) return;
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		String refuses = config.getInitParameter("refuse");
		refuse = refuses.split(",");
	}

}
